package v3.chapter4.lockMethodTest1;

import java.util.concurrent.locks.ReentrantLock;

public class Run {

	public static void main(String[] args) {
		Service service = new Service();
		service.serviceMethod1();
	}

}


class Service{
	private ReentrantLock lock=new ReentrantLock();
	
	public void serviceMethod1() {
		try {
			lock.lock();
			System.out.println("serviceMethod1 getHoldCount=" + lock.getHoldCount());
			serviceMethod2();
		}finally {
			System.out.println("1");
			lock.unlock();
		}
	}
	
	public void serviceMethod2() {
		try {
			lock.lock();
			System.out.println("serviceMethod2 getHoldCount=" + lock.getHoldCount());
		}finally {
			System.out.println("2");
			lock.unlock();
		}
	}
}